package com.xidian.zhiancloud.controller.ledgerManagerment.relatedPart;

import com.xidian.zhiancloud.util.zyf.ExcelUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.LinkedList;
import java.util.List;

/**
 * @Author: Summerless
 * @Date: 2021/3/3 15:21
 */
@RestController
@RequestMapping("/excelTest")
public class TestController {
    @GetMapping("/test")
    public void test(HttpServletResponse response) throws IOException {
        List<Student> students = new LinkedList<>();
        List<Teacher> teachers = new LinkedList<>();
        for (int i = 0; i < 10; ++i) {
            Student student = new Student();
            student.setId("student_id_" + i);
            student.setName("student_name_" + i);
            students.add(student);
        }
        for(int i=0;i<3;i++){
            Teacher teacher = new Teacher();
            teacher.setName("teacher_name_"+i);
            teacher.setId("teacher_id_"+i);
            List<Student> list = new LinkedList<>();
            list.add(students.get(i*3));
            list.add(students.get(i*3+1));
            list.add(students.get(i*3+2));
            teacher.setStudents(list);
            teachers.add(teacher);
        }
        ExcelUtils.exportExcel(teachers,"导出","sheetname",Teacher.class,"文件名",response);
    }
}
